<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录</title>
</head>
<body>
  <form id="signInForm" action="" class="">
    账号 <input name="username" type="text"><br>
    密码 <input name="password" type="text"><br>
    <button type="submit">登录</button>
  </form>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script>
    const $form= $("#signInForm")
    $form.on("submit",(e)=>{
      e.preventDefault()
      const username=$form.find("input[name=username]").val()
      const password=$form.find("input[name=password]").val()
      $.ajax({
        url:"/sign_in",
        method:"POST",
        contentType:"text/json;charset=utf-8",
        data:JSON.stringify({username,password})
      }).then((data)=>{
        alert("登录成功")
        location.href="/home.html"
      },(err)=>{
        alert("登录失败")
        console.log(err);
      })
    })
  </script>
</body>
</html>